/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.manage.core.service;

import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceInvoke;
import info.peigen.hotpot.manage.core.service.facade.OrganizationServiceFacade;
import info.peigen.hotpot.manage.core.service.order.OrganizationCreateOrder;
import info.peigen.hotpot.manage.core.service.order.OrganizationEditOrder;
import info.peigen.hotpot.manage.core.service.result.OrganizationCreateResult;
import info.peigen.hotpot.manage.core.service.result.OrganizationEditResult;
import org.noear.solon.annotation.Component;

/**
 * <b>(OrganizationService)</b>
 * "组织机构" 服务实现
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2024-06-28
 */
@SuppressWarnings({"unused", "rawtypes"})
@Component
public class OrganizationService extends AbstractHotpotManageService implements OrganizationServiceFacade {

    @Override
    public OrganizationCreateResult create(OrganizationCreateOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new OrganizationCreateResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(organizationCreateProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(organizationStoreProcessor, organizationCreateResultProcessor);
            }
        });
        return (OrganizationCreateResult) serviceContext.getResult();
    }

    @Override
    public OrganizationEditResult edit(OrganizationEditOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new OrganizationEditResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addPreProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(organizationActiveProcessor);
            }

            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(organizationEditProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(organizationStoreProcessor, organizationEditResultProcessor);
            }
        });
        return (OrganizationEditResult) serviceContext.getResult();
    }
}